package com.inei.eea2014.controller.activity;

import com.inei.eea2014.R;
import com.inei.eea2014.controller.Capitulo4Controller;
import com.inei.eea2014.model.entity.Capitulo3;
import com.inei.eea2014.model.entity.Capitulo4;
import com.inei.eea2014.tools.Mensaje;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TableRow;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class CapituloIV_Fragment extends Fragment {

	// componentes
	private View root;
	private TableRow trOpcional;
	private EditText etRuc, etInf, etTel, etMov, etRed, etInte, etC4_21,
			etC4_22, etC4_3, etC4_5, etC4_61, etC4_62, etC4_63, etC4_71,
			etC4_72, etC4_73, etC4_8, etC4_11_O, etC4_a, etC4_g;
	private RadioButton rbInf1, rbInf2, rbTel1, rbTel2, rbMov1, rbMov2, rbRed1,
			rbRed2, rbInte1, rbInte2, rbIntr1, rbIntr2, rbExtr1, rbExtr2,
			rbC4_51, rbC4_52, rbC4_61, rbC4_62, rbC4_71, rbC4_72, rbC4_101,
			rbC4_102, rbC4_131, rbC4_132, rbC4_141, rbC4_142, rbC4_151,
			rbC4_152, rbC4_161, rbC4_162, rbC4_171, rbC4_172;
	private CheckBox cbC4_11_11, cbC4_11_12, cbC4_11_13, cbC4_11_14,
			cbC4_11_21, cbC4_11_22, cbC4_11_23, cbC4_11_O, cbC4_a1, cbC4_a2,
			cbC4_a3, cbC4_a4, cbC4_b1, cbC4_c1, cbC4_d1, cbC4_e1, cbC4_f1,
			cbC4_g1;

	// variables
	private String RUC;
	private String USUARIO;
	private Capitulo4Controller cap4Con;
	private Capitulo4 obj;
	private Mensaje m;
	private boolean nuevo = false;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		root = inflater
				.inflate(R.layout.fragment_capitulo_iv, container, false);

		return root;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);

		cap4Con = new Capitulo4Controller(getActivity());
		m = new Mensaje(getActivity());

		IniciarComponentes();

		AgregarEventos();

		CargarDatos();
	}

	private void IniciarComponentes() {
		trOpcional = (TableRow) root.findViewById(R.id.trOpcional);

		etRuc = (EditText) root.findViewById(R.id.etRuc);
		etInf = (EditText) root.findViewById(R.id.etInf);
		etTel = (EditText) root.findViewById(R.id.etTel);
		etMov = (EditText) root.findViewById(R.id.etMov);
		etRed = (EditText) root.findViewById(R.id.etRed);
		etInte = (EditText) root.findViewById(R.id.etInte);
		etC4_21 = (EditText) root.findViewById(R.id.etC4_21);
		etC4_22 = (EditText) root.findViewById(R.id.etC4_22);
		etC4_3 = (EditText) root.findViewById(R.id.etC4_3);
		etC4_5 = (EditText) root.findViewById(R.id.etC4_5);
		etC4_61 = (EditText) root.findViewById(R.id.etC4_61);
		etC4_62 = (EditText) root.findViewById(R.id.etC4_62);
		etC4_63 = (EditText) root.findViewById(R.id.etC4_63);
		etC4_71 = (EditText) root.findViewById(R.id.etC4_71);
		etC4_72 = (EditText) root.findViewById(R.id.etC4_72);
		etC4_73 = (EditText) root.findViewById(R.id.etC4_73);
		etC4_8 = (EditText) root.findViewById(R.id.etC4_8);
		etC4_11_O = (EditText) root.findViewById(R.id.etC4_11_O);
		etC4_a = (EditText) root.findViewById(R.id.etC4_a);
		etC4_g = (EditText) root.findViewById(R.id.etC4_g);

		rbInf1 = (RadioButton) root.findViewById(R.id.rbInf1);
		rbInf2 = (RadioButton) root.findViewById(R.id.rbInf2);
		rbTel1 = (RadioButton) root.findViewById(R.id.rbTel1);
		rbTel2 = (RadioButton) root.findViewById(R.id.rbTel2);
		rbMov1 = (RadioButton) root.findViewById(R.id.rbMov1);
		rbMov2 = (RadioButton) root.findViewById(R.id.rbMov2);
		rbRed1 = (RadioButton) root.findViewById(R.id.rbRed1);
		rbRed2 = (RadioButton) root.findViewById(R.id.rbRed2);
		rbInte1 = (RadioButton) root.findViewById(R.id.rbInte1);
		rbInte2 = (RadioButton) root.findViewById(R.id.rbInte2);
		rbIntr1 = (RadioButton) root.findViewById(R.id.rbIntr1);
		rbIntr2 = (RadioButton) root.findViewById(R.id.rbIntr2);
		rbExtr1 = (RadioButton) root.findViewById(R.id.rbExtr1);
		rbExtr2 = (RadioButton) root.findViewById(R.id.rbExtr2);
		rbC4_51 = (RadioButton) root.findViewById(R.id.rbC4_51);
		rbC4_52 = (RadioButton) root.findViewById(R.id.rbC4_52);
		rbC4_61 = (RadioButton) root.findViewById(R.id.rbC4_61);
		rbC4_62 = (RadioButton) root.findViewById(R.id.rbC4_62);
		rbC4_71 = (RadioButton) root.findViewById(R.id.rbC4_71);
		rbC4_72 = (RadioButton) root.findViewById(R.id.rbC4_72);
		rbC4_101 = (RadioButton) root.findViewById(R.id.rbC4_101);
		rbC4_102 = (RadioButton) root.findViewById(R.id.rbC4_102);
		rbC4_131 = (RadioButton) root.findViewById(R.id.rbC4_131);
		rbC4_132 = (RadioButton) root.findViewById(R.id.rbC4_132);
		rbC4_141 = (RadioButton) root.findViewById(R.id.rbC4_141);
		rbC4_142 = (RadioButton) root.findViewById(R.id.rbC4_142);
		rbC4_151 = (RadioButton) root.findViewById(R.id.rbC4_151);
		rbC4_152 = (RadioButton) root.findViewById(R.id.rbC4_152);
		rbC4_161 = (RadioButton) root.findViewById(R.id.rbC4_161);
		rbC4_162 = (RadioButton) root.findViewById(R.id.rbC4_162);
		rbC4_171 = (RadioButton) root.findViewById(R.id.rbC4_171);
		rbC4_172 = (RadioButton) root.findViewById(R.id.rbC4_172);

		cbC4_11_11 = (CheckBox) root.findViewById(R.id.cbC4_11_11);
		cbC4_11_12 = (CheckBox) root.findViewById(R.id.cbC4_11_12);
		cbC4_11_13 = (CheckBox) root.findViewById(R.id.cbC4_11_13);
		cbC4_11_14 = (CheckBox) root.findViewById(R.id.cbC4_11_14);
		cbC4_11_21 = (CheckBox) root.findViewById(R.id.cbC4_11_21);
		cbC4_11_22 = (CheckBox) root.findViewById(R.id.cbC4_11_22);
		cbC4_11_23 = (CheckBox) root.findViewById(R.id.cbC4_11_23);
		cbC4_11_O = (CheckBox) root.findViewById(R.id.cbC4_11_O);
		cbC4_a1 = (CheckBox) root.findViewById(R.id.cbC4_a1);
		cbC4_a2 = (CheckBox) root.findViewById(R.id.cbC4_a2);
		cbC4_a3 = (CheckBox) root.findViewById(R.id.cbC4_a3);
		cbC4_a4 = (CheckBox) root.findViewById(R.id.cbC4_a4);
		cbC4_b1 = (CheckBox) root.findViewById(R.id.cbC4_b1);
		cbC4_c1 = (CheckBox) root.findViewById(R.id.cbC4_c1);
		cbC4_d1 = (CheckBox) root.findViewById(R.id.cbC4_d1);
		cbC4_e1 = (CheckBox) root.findViewById(R.id.cbC4_e1);
		cbC4_f1 = (CheckBox) root.findViewById(R.id.cbC4_f1);
		cbC4_g1 = (CheckBox) root.findViewById(R.id.cbC4_g1);

		etInf.setEnabled(false);
		etTel.setEnabled(false);
		etMov.setEnabled(false);
		etRed.setEnabled(false);
		etInte.setEnabled(false);
		etC4_61.setEnabled(false);
		etC4_62.setEnabled(false);
		etC4_63.setEnabled(false);
		etC4_71.setEnabled(false);
		etC4_72.setEnabled(false);
		etC4_73.setEnabled(false);
		etC4_11_O.setEnabled(false);
		etC4_a.setEnabled(false);
		etC4_g.setEnabled(false);

		trOpcional.setVisibility(View.GONE);
	}

	private void AgregarEventos() {
		EventoSiNo(rbInf1);
		EventoSiNo(rbInf2);
		EventoSiNo(rbTel1);
		EventoSiNo(rbTel2);
		EventoSiNo(rbMov1);
		EventoSiNo(rbMov2);
		EventoSiNo(rbRed1);
		EventoSiNo(rbRed2);
		EventoSiNo(rbInte1);
		EventoSiNo(rbInte2);
		EventoSiNo(rbC4_61);
		EventoSiNo(rbC4_62);
		EventoSiNo(rbC4_71);
		EventoSiNo(rbC4_72);

		EventoOtro(cbC4_11_O);
		EventoOtro(cbC4_a4);
		EventoOtro(cbC4_g1);
	}

	private void EventoSiNo(final RadioButton rb) {
		rb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if (rb == rbInf1 || rb == rbInf2) {
					etInf.requestFocus();
					etInf.setEnabled(rbInf1.isChecked() ? true : false);
					etInf.setText(rbInf2.isChecked() ? "" : null);
				}
				if (rb == rbTel1 || rb == rbTel2) {
					etTel.requestFocus();
					etTel.setEnabled(rbTel1.isChecked() ? true : false);
					etTel.setText(rbTel2.isChecked() ? "" : null);
				}
				if (rb == rbMov1 || rb == rbMov2) {
					etMov.requestFocus();
					etMov.setEnabled(rbMov1.isChecked() ? true : false);
					etMov.setText(rbMov2.isChecked() ? "" : null);
				}
				if (rb == rbRed1 || rb == rbRed2) {
					etRed.requestFocus();
					etRed.setEnabled(rbRed1.isChecked() ? true : false);
					etRed.setText(rbRed2.isChecked() ? "" : null);
				}
				if (rb == rbInte1 || rb == rbInte2) {
					etInte.requestFocus();
					etInte.setEnabled(rbInte1.isChecked() ? true : false);
					etInte.setText(rbInte2.isChecked() ? "" : null);
					trOpcional.setVisibility(rbInte1.isChecked() ? View.VISIBLE
							: View.GONE);
				}
				if (rb == rbC4_61 || rb == rbC4_62) {
					etC4_61.requestFocus();
					etC4_61.setEnabled(rbC4_61.isChecked() ? true : false);
					etC4_61.setText(rbC4_62.isChecked() ? "" : null);
					etC4_62.setEnabled(rbC4_61.isChecked() ? true : false);
					etC4_62.setText(rbC4_62.isChecked() ? "" : null);
					etC4_63.setEnabled(rbC4_61.isChecked() ? true : false);
					etC4_63.setText(rbC4_62.isChecked() ? "" : null);
				}
				if (rb == rbC4_71 || rb == rbC4_72) {
					etC4_71.requestFocus();
					etC4_71.setEnabled(rbC4_71.isChecked() ? true : false);
					etC4_71.setText(rbC4_72.isChecked() ? "" : null);
					etC4_72.setEnabled(rbC4_71.isChecked() ? true : false);
					etC4_72.setText(rbC4_72.isChecked() ? "" : null);
					etC4_73.setEnabled(rbC4_71.isChecked() ? true : false);
					etC4_73.setText(rbC4_72.isChecked() ? "" : null);
				}
			}
		});
	}

	private void EventoOtro(final CheckBox cb) {
		cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView,
					boolean isChecked) {
				if (cb == cbC4_11_O) {
					etC4_11_O.requestFocus();
					etC4_11_O.setEnabled(cbC4_11_O.isChecked() ? true : false);
					etC4_11_O.setText(cbC4_11_O.isChecked() ? null : "");
				}
				if (cb == cbC4_a4) {
					etC4_a.requestFocus();
					etC4_a.setEnabled(cbC4_a4.isChecked() ? true : false);
					etC4_a.setText(cbC4_a4.isChecked() ? null : "");
				}
				if (cb == cbC4_g1) {
					etC4_g.requestFocus();
					etC4_g.setEnabled(cbC4_g1.isChecked() ? true : false);
					etC4_g.setText(cbC4_g1.isChecked() ? null : "");
				}
			}
		});
	}

	private void CargarDatos() {
		RUC = getArguments().getString("RUC");
		USUARIO = getArguments().getString("USUARIO");

		etRuc.setText(RUC);

		obj = new Capitulo4(RUC, USUARIO);

		obj = cap4Con.Cap04Obtener(obj);
		if (obj != null) {
			// A
			rbInf1.setChecked(Check(obj.getC0T01_001_01_T()));
			rbInf2.setChecked(Check(obj.getC0T01_001_02_T()));
			etInf.setText(obj.getC0T01_002_01_T());
			rbTel1.setChecked(Check(obj.getC0T01_003_01_T()));
			rbTel2.setChecked(Check(obj.getC0T01_003_02_T()));
			etTel.setText(obj.getC0T01_004_01_T());
			rbMov1.setChecked(Check(obj.getC0T01_005_01_T()));
			rbMov2.setChecked(Check(obj.getC0T01_005_02_T()));
			etMov.setText(obj.getC0T01_006_01_T());
			rbRed1.setChecked(Check(obj.getC0T01_007_01_T()));
			rbRed2.setChecked(Check(obj.getC0T01_007_02_T()));
			etRed.setText(obj.getC0T01_008_01_T());
			rbInte1.setChecked(Check(obj.getC0T01_009_01_T()));
			rbInte2.setChecked(Check(obj.getC0T01_009_02_T()));
			etInte.setText(obj.getC0T01_010_01_T());
			rbIntr1.setChecked(Check(obj.getC0T01_011_01_T()));
			rbIntr2.setChecked(Check(obj.getC0T01_011_02_T()));
			rbExtr1.setChecked(Check(obj.getC0T01_012_01_T()));
			rbExtr2.setChecked(Check(obj.getC0T01_012_02_T()));
			etC4_21.setText(obj.getC0T01_013_01_T());
			etC4_22.setText(obj.getC0T01_014_01_T());
			etC4_3.setText(obj.getC0T01_015_01_T());

			// B
			etC4_5.setText(obj.getC0T02_001_01_T());
			rbC4_51.setChecked(Check(obj.getC0T02_002_01_T()));
			rbC4_52.setChecked(Check(obj.getC0T02_002_02_T()));

			// C
			rbC4_61.setChecked(Check(obj.getC0T02_003_01_T()));
			rbC4_62.setChecked(Check(obj.getC0T02_003_02_T()));
			etC4_61.setText(obj.getC0T02_004_01_T());
			etC4_62.setText(obj.getC0T02_005_01_T());
			etC4_63.setText(obj.getC0T02_006_01_T());
			rbC4_71.setChecked(Check(obj.getC0T02_007_01_T()));
			rbC4_72.setChecked(Check(obj.getC0T02_007_02_T()));
			etC4_71.setText(obj.getC0T02_008_01_T());
			etC4_72.setText(obj.getC0T02_009_01_T());
			etC4_73.setText(obj.getC0T02_010_01_T());
			etC4_8.setText(obj.getC0T02_011_01_T());

			// D
			rbC4_101.setChecked(Check(obj.getC0T03_001_01_T()));
			rbC4_102.setChecked(Check(obj.getC0T03_001_02_T()));
			cbC4_11_11.setChecked(Check(obj.getC0T03_004_01_T()));
			cbC4_11_12.setChecked(Check(obj.getC0T03_004_02_T()));
			cbC4_11_13.setChecked(Check(obj.getC0T03_004_03_T()));
			cbC4_11_14.setChecked(Check(obj.getC0T03_004_04_T()));
			cbC4_11_21.setChecked(Check(obj.getC0T03_004_05_T()));
			cbC4_11_22.setChecked(Check(obj.getC0T03_004_06_T()));
			cbC4_11_23.setChecked(Check(obj.getC0T03_004_07_T()));
			cbC4_11_O.setChecked(Check(obj.getC0T03_004_08_T()));
			etC4_11_O.setText(obj.getC0T03_005_01_T());
			cbC4_a1.setChecked(Check(obj.getC0T03_006_01_T()));
			cbC4_a2.setChecked(Check(obj.getC0T03_006_02_T()));
			cbC4_a3.setChecked(Check(obj.getC0T03_006_03_T()));
			cbC4_a4.setChecked(Check(obj.getC0T03_006_04_T()));
			cbC4_b1.setChecked(Check(obj.getC0T03_006_05_T()));
			cbC4_c1.setChecked(Check(obj.getC0T03_006_06_T()));
			cbC4_d1.setChecked(Check(obj.getC0T03_006_07_T()));
			cbC4_e1.setChecked(Check(obj.getC0T03_006_08_T()));
			cbC4_f1.setChecked(Check(obj.getC0T03_006_09_T()));
			cbC4_g1.setChecked(Check(obj.getC0T03_006_10_T()));
			etC4_a.setText(obj.getC0T03_007_01_T());
			etC4_g.setText(obj.getC0T03_008_01_T());

			// F
			rbC4_131.setChecked(Check(obj.getC0T04_001_01_T()));
			rbC4_132.setChecked(Check(obj.getC0T04_001_02_T()));
			rbC4_141.setChecked(Check(obj.getC0T04_002_01_T()));
			rbC4_142.setChecked(Check(obj.getC0T04_002_02_T()));
			rbC4_151.setChecked(Check(obj.getC0T04_003_01_T()));
			rbC4_152.setChecked(Check(obj.getC0T04_003_02_T()));
			rbC4_161.setChecked(Check(obj.getC0T04_004_01_T()));
			rbC4_162.setChecked(Check(obj.getC0T04_004_02_T()));

			// G
			rbC4_171.setChecked(Check(obj.getC0T04_005_01_T()));
			rbC4_172.setChecked(Check(obj.getC0T04_005_02_T()));
		}
	}

	private boolean Check(String text) {
		if (text == null) {
			return false;
		} else {
			return text.equals("1") ? true : false;
		}
	}

	public void ValidarCap() {
		// TODO Auto-generated method stub

	}

	public void GuardarCap() {
		if (obj == null) {
			nuevo = true;
			obj = new Capitulo4(RUC, USUARIO);
		}

		// A
		obj.setC0T01_001_01_T(rbInf1.isChecked() ? "1" : "0");
		obj.setC0T01_001_02_T(rbInf2.isChecked() ? "1" : "0");
		obj.setC0T01_002_01_T(etInf.getText().toString());
		obj.setC0T01_003_01_T(rbTel1.isChecked() ? "1" : "0");
		obj.setC0T01_003_02_T(rbTel2.isChecked() ? "1" : "0");
		obj.setC0T01_004_01_T(etTel.getText().toString());
		obj.setC0T01_005_01_T(rbMov1.isChecked() ? "1" : "0");
		obj.setC0T01_005_02_T(rbMov2.isChecked() ? "1" : "0");
		obj.setC0T01_006_01_T(etMov.getText().toString());
		obj.setC0T01_007_01_T(rbRed1.isChecked() ? "1" : "0");
		obj.setC0T01_007_02_T(rbRed2.isChecked() ? "1" : "0");
		obj.setC0T01_008_01_T(etRed.getText().toString());
		obj.setC0T01_009_01_T(rbInte1.isChecked() ? "1" : "0");
		obj.setC0T01_009_02_T(rbInte2.isChecked() ? "1" : "0");
		obj.setC0T01_010_01_T(etInte.getText().toString());
		obj.setC0T01_011_01_T(rbIntr1.isChecked() ? "1" : "0");
		obj.setC0T01_011_02_T(rbIntr2.isChecked() ? "1" : "0");
		obj.setC0T01_012_01_T(rbExtr1.isChecked() ? "1" : "0");
		obj.setC0T01_012_02_T(rbExtr2.isChecked() ? "1" : "0");
		obj.setC0T01_013_01_T(etC4_21.getText().toString());
		obj.setC0T01_014_01_T(etC4_22.getText().toString());
		obj.setC0T01_015_01_T(etC4_3.getText().toString());

		// B
		obj.setC0T02_001_01_T(etC4_5.getText().toString());
		obj.setC0T02_002_01_T(rbC4_51.isChecked() ? "1" : "0");
		obj.setC0T02_002_02_T(rbC4_52.isChecked() ? "1" : "0");

		// C
		obj.setC0T02_003_01_T(rbC4_61.isChecked() ? "1" : "0");
		obj.setC0T02_003_02_T(rbC4_62.isChecked() ? "1" : "0");
		obj.setC0T02_004_01_T(etC4_61.getText().toString());
		obj.setC0T02_005_01_T(etC4_62.getText().toString());
		obj.setC0T02_006_01_T(etC4_63.getText().toString());
		obj.setC0T02_007_01_T(rbC4_71.isChecked() ? "1" : "0");
		obj.setC0T02_007_02_T(rbC4_72.isChecked() ? "1" : "0");
		obj.setC0T02_008_01_T(etC4_71.getText().toString());
		obj.setC0T02_009_01_T(etC4_72.getText().toString());
		obj.setC0T02_010_01_T(etC4_73.getText().toString());
		obj.setC0T02_011_01_T(etC4_8.getText().toString());

		// D
		obj.setC0T03_001_01_T(rbC4_101.isChecked() ? "1" : "0");
		obj.setC0T03_001_02_T(rbC4_102.isChecked() ? "1" : "0");
		obj.setC0T03_004_01_T(cbC4_11_11.isChecked() ? "1" : "0");
		obj.setC0T03_004_02_T(cbC4_11_12.isChecked() ? "1" : "0");
		obj.setC0T03_004_03_T(cbC4_11_13.isChecked() ? "1" : "0");
		obj.setC0T03_004_04_T(cbC4_11_14.isChecked() ? "1" : "0");
		obj.setC0T03_004_05_T(cbC4_11_21.isChecked() ? "1" : "0");
		obj.setC0T03_004_06_T(cbC4_11_22.isChecked() ? "1" : "0");
		obj.setC0T03_004_07_T(cbC4_11_23.isChecked() ? "1" : "0");
		obj.setC0T03_004_08_T(cbC4_11_O.isChecked() ? "1" : "0");
		obj.setC0T03_005_01_T(etC4_11_O.getText().toString());
		obj.setC0T03_006_01_T(cbC4_a1.isChecked() ? "1" : "0");
		obj.setC0T03_006_02_T(cbC4_a2.isChecked() ? "1" : "0");
		obj.setC0T03_006_03_T(cbC4_a3.isChecked() ? "1" : "0");
		obj.setC0T03_006_04_T(cbC4_a4.isChecked() ? "1" : "0");
		obj.setC0T03_006_05_T(cbC4_b1.isChecked() ? "1" : "0");
		obj.setC0T03_006_06_T(cbC4_c1.isChecked() ? "1" : "0");
		obj.setC0T03_006_07_T(cbC4_d1.isChecked() ? "1" : "0");
		obj.setC0T03_006_08_T(cbC4_e1.isChecked() ? "1" : "0");
		obj.setC0T03_006_09_T(cbC4_f1.isChecked() ? "1" : "0");
		obj.setC0T03_006_10_T(cbC4_g1.isChecked() ? "1" : "0");
		obj.setC0T03_007_01_T(etC4_a.getText().toString());
		obj.setC0T03_008_01_T(etC4_g.getText().toString());

		// F
		obj.setC0T04_001_01_T(rbC4_131.isChecked() ? "1" : "0");
		obj.setC0T04_001_02_T(rbC4_132.isChecked() ? "1" : "0");
		obj.setC0T04_002_01_T(rbC4_141.isChecked() ? "1" : "0");
		obj.setC0T04_002_02_T(rbC4_142.isChecked() ? "1" : "0");
		obj.setC0T04_003_01_T(rbC4_151.isChecked() ? "1" : "0");
		obj.setC0T04_003_02_T(rbC4_152.isChecked() ? "1" : "0");
		obj.setC0T04_004_01_T(rbC4_161.isChecked() ? "1" : "0");
		obj.setC0T04_004_02_T(rbC4_162.isChecked() ? "1" : "0");

		// G
		obj.setC0T04_005_01_T(rbC4_171.isChecked() ? "1" : "0");
		obj.setC0T04_005_02_T(rbC4_172.isChecked() ? "1" : "0");

		if (nuevo) {
			if (cap4Con.Cap04Insertar(obj) > 0) {
				m.Exito("SE GRABO CON EXITO");
				nuevo = false;
			} else {
				m.Error("ERROR AL GRABAR");
			}
		} else {
			if (cap4Con.Cap04Modificar(obj) > 0) {
				m.Exito("SE MODIFICO CON EXITO");
			} else {
				m.Error("ERROR AL MODIFICAR");
			}
		}
	}
}
